﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

//using Xunit;
//using Assert = Xunit.Assert;

namespace SaleOfMoviesSystem.Xml.NunitTest.template
{
    public class simple_TwoSum
    {
        public int[] TwoSum(int[] nums, int target)
        {
            int[] res = { 0, 0 };
            int len = nums.Length;
            Dictionary<int, int> dict = new Dictionary<int, int>();
            for (int i = 0; i < len; i++)
            {
                int query = target - nums[i];
                if (dict.ContainsKey(query))
                {
                    int min = (i <= dict[query]) ? i : dict[query];
                    int max = (i <= dict[query]) ? dict[query] : i;
                    return new int[] { min, max };
                }
                else if (!dict.ContainsKey(nums[i]))
                {
                    dict.Add(nums[i], i);
                }
            }

            return res;
        }
    }

    //--------------------------------XUnit------------------------------------------
    //public class Tests
    //{
    //    [Fact]
    //    public void Test1()
    //    {
    //        simple_TwoSum _nUnit = new simple_TwoSum();
    //        //Assert.Pass();
    //        var result1 = _nUnit.TwoSum(new int[] { 2, 7, 11, 15 }, 9);
    //        var result2 = _nUnit.TwoSum(new int[] { 2, 3, 11, 3 }, 6);

    //        Assert.Equal(new int[] { 0, 1 }, result1);
    //        Assert.Equal(new int[] { 1, 3 }, result2);
    //    }
    //}

    //--------------------------------NUnit------------------------------------------
    [TestFixture]
    public class Tests
    {
        private simple_TwoSum _nUnit;

        [SetUp]
        public void Setup()
        {
            _nUnit = new simple_TwoSum();
        }

        [Test]
        public void Test1()
        {
            //Assert.Pass();
            var result1 = _nUnit.TwoSum(new int[] { 2, 7, 11, 15 }, 9);
            var result2 = _nUnit.TwoSum(new int[] { 2, 3, 11, 3 }, 6);

            Assert.AreEqual(new int[] { 0, 1 }, result1);
            Assert.AreEqual(new int[] { 1, 3 }, result2);
        }
    }
}